<template>
  <div class="login-container">
    <!-- 主体图片 -->
    <div class="login-left">
      <img src="@/assets/img/login_img.png" alt="" />
    </div>

    <!-- 登录区域 -->
    <div class="login-box">
      <!-- 头像 -->
      <div class="avatar-box">
        <img src="@/assets/img/login_logo.png" alt="" />
      </div>
      <!-- 标题 -->
      <div class="title">酒店管理</div>
      <!-- 登录的表单 -->
      <el-form ref="loginFormRef" :model="loginForm"  class="login_form">
        <el-form-item prop="username">
          <el-input v-model="loginForm.username" prefix-icon="el-icon-user-solid"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input v-model="loginForm.password" prefix-icon="el-icon-key" type="password"></el-input>
        </el-form-item>
        <el-form-item class="btns">
          <el-button type="primary" @click="resetLoginform">登录</el-button>
          <el-button type="info" @click="resetLoginForm">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 存储表单的数据
      loginForm: {
        username: 'admin',
        password: '123456',
      },
      // 定义表单的验证规则
      loginFormRules: {
        username: [
          { required: true, message: '请输入登录账户', trigger: 'blur' },
          { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' },
        ],
        password: [
          { required: true, message: '请输入登录密码', trigger: 'blur' },
          { min: 6, max: 15, message: '长度在 6 到 15 个字符', trigger: 'blur' },
        ],
      },
    }
  },
  methods: {
    resetLoginform() {
      if (this.loginForm.username === 'admin' && this.loginForm.password === '123456') {
        this.$router.replace('/home')
        this.$message.success('登录成功')
      } else {
        return this.$message.error('登录失败')
      }
    },
    resetLoginForm() {
      this.$refs.loginFormRef.resetFields()
    },
  },
}
</script>

<style>
@import '../assets/css/header/app.scss';
@import '../assets/css/header/login.scss';
</style>